package com.amigo.online.provider.merchant.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.LongTypeHandler;
import org.springframework.stereotype.Component;

import com.amigo.online.common.core.mybatis.MyMapper;
import com.amigo.online.common.param.common.KeyValueModel;
import com.amigo.online.provider.merchant.model.entity.Category;


@Mapper
@Component
public interface CategoryMapper extends MyMapper<Category> {

    /**
     * @throws
     * @Title: findLabelCategoryListByLabelId
     * @Description: (这里用一句话描述这个方法的作用)
     * @param: @param labelId
     * @return: void
     */
    @Select("select id, ${name} as name from category_tbl where p_id = #{labelId}")
    @Results({
            @Result(column = "id", property = "id", javaType = Long.class, typeHandler = LongTypeHandler.class),
            @Result(column = "name", property = "value", javaType = String.class)
    })
    List<KeyValueModel<Long, String>> findLabelCategoryListByLabelId(@Param("labelId") Integer labelId, @Param("name") String language);

    List<Category> getHomePageCategory();

    @Select("select id, ${name} as name from category_tbl where id = #{categoryId}")
    String getCategoryNameById(@Param("categoryId") Long categoryId, @Param("name") String language);

    @MapKey("id")
    Map<Long, Category> getCategoryListByIdList(@Param("ids") List<Long> ids);

}